/**
 * @file       st7735.h
 * @author     mz8023yt
 * @email      mz8023yt@163.com
 * @version    V1.0
 * @date       2022-03-13
 * @brief      st7735 lcd driver
 */

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>

#ifndef LOW
#define LOW 0
#endif

#ifndef HIGH
#define HIGH 1
#endif

#ifndef RGB565_WHITE
#define RGB565_WHITE 0xFFFF
#endif

#ifndef RGB565_BLACK
#define RGB565_BLACK 0x0000
#endif

#ifndef RGB565_RED
#define RGB565_RED 0xF800
#endif

#ifndef RGB565_GREEN
#define RGB565_GREEN 0x07E0
#endif

#ifndef RGB565_BLUE
#define RGB565_BLUE 0x001F
#endif

/**
 * @brief ST7735
 */
struct st7735 {
	struct {
		struct {
			uint8_t width;  // 132 max
			uint8_t height; // 162 max
		} fix;
		struct {
			int orien;
		} var;
	} cfg;
	struct {
		struct {
			void (*write)(uint8_t* bytes, uint32_t len);
		} spi;
		struct {
			void (*msleep)(int ms);
		} time;
		struct {
			void (*rst)(int val);
			void (*bl)(int val);
			void (*dc)(int val);
		} pin;
	} ops;
};

void st7735_init(struct st7735* lcd);
void st7735_point_draw(struct st7735* lcd, uint8_t x, uint8_t y, uint16_t color);
void st7735_rect_fill(struct st7735* lcd, uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2, uint16_t* color);
void st7735_screen_fill(struct st7735* lcd, uint16_t* color);
void st7735_screen_test(struct st7735* lcd, uint16_t color);

#ifdef __cplusplus
}
#endif
